# MySQL Schema Sync Tool Makefile

BINARY_NAME=mysql-sync
VERSION=2025.1
BUILD_DIR=build
DIST_DIR=dist

# 默认目标
.PHONY: all
all: clean build

# 显示帮助信息
.PHONY: help
help:
	@echo "MySQL Schema Sync Tool Build System"
	@echo "Available targets:"
	@echo "  build          - 构建当前平台的二进制文件"
	@echo "  build-static   - 构建静态链接的二进制文件"
	@echo "  test           - 运行测试"
	@echo "  clean          - 清理构建文件"
	@echo "  fmt            - 格式化代码"
	@echo "  deps           - 下载依赖"
	@echo "  version        - 显示版本信息"

# 构建当前平台
.PHONY: build
build: deps
	@echo "Building $(BINARY_NAME) for current platform..."
	@mkdir -p $(BUILD_DIR)
	go build -o $(BUILD_DIR)/$(BINARY_NAME) main.go
	@echo "Build completed: $(BUILD_DIR)/$(BINARY_NAME)"

# 构建静态链接版本
.PHONY: build-static
build-static: deps
	@echo "Building static $(BINARY_NAME)..."
	@mkdir -p $(BUILD_DIR)
	CGO_ENABLED=0 go build -tags netgo -ldflags '-w -s -extldflags "-static"' -o $(BUILD_DIR)/$(BINARY_NAME)-static main.go
	@echo "Static build completed: $(BUILD_DIR)/$(BINARY_NAME)-static"

# 运行测试
.PHONY: test
test:
	@echo "Running tests..."
	go test -v ./...

# 清理构建文件
.PHONY: clean
clean:
	@echo "Cleaning build files..."
	rm -rf $(BUILD_DIR) $(DIST_DIR)
	@echo "Clean completed"

# 格式化代码
.PHONY: fmt
fmt:
	@echo "Formatting code..."
	go fmt ./...
	@echo "Code formatted"

# 下载依赖
.PHONY: deps
deps:
	@echo "Downloading dependencies..."
	go mod download
	@echo "Dependencies downloaded"

# 显示版本信息
.PHONY: version
version:
	@echo "MySQL Schema Sync Tool"
	@echo "Version: $(VERSION)"

# 快速构建和测试
.PHONY: quick
quick: deps test build
	@echo "Quick build completed"
